import { Component } from '@angular/core';
import { NavController, NavParams, LoadingController } from 'ionic-angular';
import { UserProvider } from '../../../providers/service/user'

/**
 * Generated class for the SettingPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@Component({
    selector: 'page-setting',
    templateUrl: 'setting.html',
})
export class SettingPage {

    constructor(public navCtrl: NavController,
        public userProvider: UserProvider,
        public loadingCtrl: LoadingController,
        public navParams: NavParams) {
    }

    noticeFlag = true;
    ionViewDidLoad() {
        //console.log('ionViewDidLoad SettingPage');
        this.userProvider.getNoticeFlag({}).then((res: any) => {
            console.log(res);
            this.noticeFlag = res.noticeFlag
        }, err => {
            console.log(err);
        });
    }

    save() {
        let loading = this.loadingCtrl.create({
            content: '保存中，请稍等'
        });
        loading.present();
        this.userProvider.setNoticeFlag({noticeFlag: this.noticeFlag}).then(res=>{
            loading.setContent("修改成功");
            setTimeout(() => {
                loading.dismiss();
            }, 500);
        },err=>{
            loading.dismiss();
        })
    }

}
